package com.chaoyong.higo.activity;

import com.chaoyong.higo.R;
import com.chaoyong.higo.adapter.SettingsAdapter;
import com.chaoyong.higo.base.BaseActivity;
import com.chaoyong.higo.fragment.FragWodeduobao;
import com.chaoyong.higo.utils.AtyManager;
import com.chaoyong.higo.utils.PrefUtils;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 我的云筹-设置
 * @author zk
 *
 */
public class MySettingsActivity extends BaseActivity implements OnItemClickListener {

	private LinearLayout base_left_iv;// 左侧返回按钮
	private TextView base_title_tv;// 标题
	private TextView base_right_tv;// 标题右侧文字

	private ListView setting_list_view;
	private Button setting_exit_btn;// 退出登录
	private SettingsAdapter adapter;

	@Override
	public int layoutResID() {
		return R.layout.activity_settings;
	}

	@Override
	public void findView() {
		findTitleIds();

		setting_list_view = (ListView) findViewById(R.id.setting_list_view);
		setting_exit_btn = (Button) findViewById(R.id.setting_exit_btn);
	}

	@Override
	public void init() {
		setting_exit_btn.setOnClickListener(this);
		adapter = new SettingsAdapter(this);
		setting_list_view.setAdapter(adapter);

		setting_list_view.setOnItemClickListener(this);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.base_left_iv://title左侧返回
			this.finish();
			break;
		case R.id.setting_exit_btn://退出登录
			/*PrefUtils.setString(this, "userId", "");
			PrefUtils.setString(this, "userName", "");
			PrefUtils.setString(this, "userPwd", "");*/
			PrefUtils.setBoolean(this, "isLogin", false);
			//AtyManager.getAtyManager().appExit(getApplicationContext());
			//startActivity(new Intent(this, MainActivity.class));
			finish();
			FragWodeduobao f = new FragWodeduobao();
			//f.refresh();
			Intent intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.slide_out_to_top);
			break;
		}
	}

	private void findTitleIds() {
		base_left_iv = (LinearLayout) findViewById(R.id.base_left_iv);
		base_title_tv = (TextView) findViewById(R.id.base_title_tv);
		base_right_tv = (TextView) findViewById(R.id.baseduobao_right_tv);

		base_title_tv.setText("更多");
		base_right_tv.setVisibility(View.GONE);
		base_left_iv.setOnClickListener(this);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		switch (arg2) {
		case 0:
//			showToast("个人资料");
			startActivity(new Intent(this,PersonalDataActivity.class));
			break;
		case 1:
//			showToast("收货地址");
			startActivity(new Intent(this,ReceiptAddressActivity.class));
			break;
		case 2:
//			showToast("账户安全");
			startActivity(new Intent(this,AccountSafeActivity.class));
			break;
		/*case 3:
//			showToast("关于我们");
			startActivity(new Intent(this,AboutUsActivity.class));
			break;*/
		case 3:
//			showToast("客服热线");
			Intent intent = new Intent(Intent.ACTION_DIAL);
			Uri data = Uri.parse("tel:" + getString(R.string.tel_num));
			intent.setData(data);
			startActivity(intent);
			break;
		}
	}

}
